package com.sy.core.timeTask;

import com.sy.core.model.SyOrderInfo;
import com.sy.core.web.BaseCtl;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 取消订单定时任务
 */
@Component
public class OrderOverTimeTask extends BaseCtl {
    @Scheduled(cron = "0 */20 * * * ?")
    public void run(){
        long millions = System.currentTimeMillis()-15*60*1000;
        Date date = new Date();
        date.setTime(millions);
        String orderTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
        SyOrderInfo syOrderInfo = new SyOrderInfo();
        syOrderInfo.setOrderStatus(1);
        syOrderInfo.setOrderTime(orderTime);
        List<SyOrderInfo> syOrderInfos = orderService.selectAll(syOrderInfo);
        for (int i = 0; i <syOrderInfos.size() ; i++) {
            syOrderInfos.get(i).setOrderStatus(4);
            syOrderInfos.get(i).setOrderRecord("");
            orderService.update(syOrderInfos.get(i));
        }
        logger.info("定时任务完成，修改订单为超时");
    }
}
